// -----------------------------------------------------------------------
//  <copyright file="ServiceCollectionExtensions.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/3/21 14:30</last-date>
// -----------------------------------------------------------------------

namespace DaprPlus.EntityFrameworkCore;

/// <summary>
/// 服务集合扩展方法
/// </summary>
public static class ServiceCollectionExtensions
{
    /// <summary>
    /// 为指定的实体类型添加缓存仓储
    /// </summary>
    /// <typeparam name="TEntity">实体类型</typeparam>
    /// <param name="services">服务集合</param>
    /// <returns>服务集合</returns>
    public static IServiceCollection AddCacheRepository<TEntity>(this IServiceCollection services)
        where TEntity : class, IEntity, IAggregateRoot, ICacheable
    {
        services.AddScoped<IRepository<TEntity>, Repository<TEntity>>();
        services.Decorate<IRepository<TEntity>, CacheRepositoryDecorator<TEntity>>();
        return services;
    }
}
